<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串</title>
    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>
    <script type="module">
        //用十六进制表示
        var \u0061 = "\u0061\u0062\u0063";
        console.log(a); // abc

        //转义大的十六进制
        console.log("\uD83D\uDE91"); //ES5
        console.log("\u{1F691}"); //es6

        //返回索引处字符的代码
        console.log("\uD83D\uDE91".codePointAt(1)); // 56977
        console.log("\u{1F691}".codePointAt(1)); // 56977
        console.log("hello".codePointAt(2)); // 1080

        //获取多个字符串
        console.log(String.fromCodePoint(0x61, 0x62, 0x63)); //abc
        console.log("\u0061\u0062 " == String.fromCodePoint(0x61, 0x62)); //false

        //重复字符串
        console.log("a".repeat(6)); // "aaaaaa"

        //在字符串变量中查找特定的变量
        var str = "Hi, I am a JS Developer";
        console.log(str.includes("JS")); // "true"

        var str = "Hi, I am a JS Developer";
        console.log(str.includes("JS", 13)); //  "false"

        //查找字符串值开始的字符的匹配
        var str = "Hi, I am a JS Developer";
        console.log(str.startsWith('Hi, I am')); //"true"

        var str = "Hi, I am a JS Developer";
        console.log(str.startsWith('JS Developer', 11)); //"true"

        //查找字符串值结束的字符的匹配
        var str = "Hi, I am a JS Developer";
        console.log(str.endsWith("JS Developer")); // "true"
        console.log(str.endsWith("JS", 13)); // "true"

        //使用代理来表示特殊字符
        console.log("\u00E9"); //output 'é'
        console.log("e\u0301"); //output 'é'

        var a = "\u00E9";
        var b = "e\u0301";
        console.log(a == b);
        console.log(a.length);
        console.log(b.length);
        for (let i = 0; i < a.length; i++) {
            console.log(a[i]);
        }
        for (let i = 0; i < b.length; i++) {
            console.log(b[i]);
        }

        var a1 = "\u00E9".normalize();
        var b1 = "e\u0301".normalize();
        console.log(a1 == b1);
        console.log(a1.length);
        console.log(b1.length);
        for (let i = 0; i < a1.length; i++) {
            console.log(a1[i]);
        }
        for (let i = 0; i < b1.length; i++) {
            console.log(b[i]);
        }

        //模板字符串符
        let str1 = `hello`;
        let str2 = "hello";
        console.log(str1 === str2); // true

        var a1 = 20;
        var b1 = 10;
        var c1 = "Javascript";
        //My age is 30 and I love Javascript
        console.log("My age is " + (a1 + b1) + " and I love " + c1);

        let a2 = 20;
        let b2 = 10;
        let c2 = "Javascript";
        let letstr = `My age is ${a2 + b2} and I love ${c2}`;
        console.log(letstr); //My age is 30 and I love Javascript


        //标签函数来处理字符串
        let tag = function (strings, ...values) {
            let result = "";
            for(let i = 0; i < strings.length; i++){
                result += strings[i];
                if(i < values.length){
                    result += values[i]; // [ a3, b3, c3]
                }
            }
            return result;
        }
        let a3 = 20, b3 = 10, c3 = "Javascript";
        let str3 = tag `My age is ${a3+b3} and I love ${c3}`;
        console.log(str3); //My age is 30 and I love Javascript

        //多行字符串
        console.log("1\n2\n3");
        console.log(`1
        2
        3`);

        //获取未转义的字符
        let s = String.raw `xy\n${ 1 + 1 }z`;
        console.log(s); //xy\n2z

        let tag2 = function(strings, ...values)
        {
            return strings.raw[0]
        };
        let letstr1= tag2 `Hello \n World!!!`;
        console.log(letstr1); //Hello \n World!!!

    </script>
</head>
<body>

</body>
</html>